package com.eagle;

import com.eagle.util.StringUtil;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;

import java.io.*;

/**
 * @author qinlinsen
 */
public class StripWord {
    @Test
    public void test(){
        String s="[INFO] |  |  \\- com.fasterxml:classmate:jar:1.3.3:compile";

        String trim = s.trim();
        System.out.println(trim);
        String s1 = s.split(":")[0]
                .replace("[INFO]", "")
                .replace("|", "")
                .replace("\\-", "")
                .replace("+-","")
                .trim();
        System.out.println(s1);

    }


    @Test
    public void test2() throws FileNotFoundException {
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("人民");
        HSSFRow row = sheet.createRow(0);
        for (int i=0;i<3;i++) {
            HSSFCell cell = row.createCell(i);
            cell.setCellValue("r"+i);
        }
        try(FileOutputStream fileOutputStream = new FileOutputStream(new File("C:\\Users\\qinls\\Desktop\\a.xlsx"))){
            workbook.write(fileOutputStream);
            System.out.println("生成文件成功");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test3() throws Exception {
        HSSFWorkbook workbook=new HSSFWorkbook(new FileInputStream(new File("/Users/hatarinshou/IdeaProjects/demo-projects/jar-version-statistics/jar-version-statistics/src/main/resources/template.xlsx")));
        final HSSFSheet sheet = workbook.getSheet("Sheet1");
        final HSSFRow row = sheet.getRow(0);
        final HSSFCell cell = row.getCell(0);
        final String stringCellValue = cell.getStringCellValue();
        cell.setCellValue("test");
        workbook.write(new File("C:\\Users\\qinls\\Desktop\\a.xlsx"));
        System.out.println(stringCellValue);
    }

    @Test
    public void test6() throws Exception{
        FileInputStream fileInputStream = new FileInputStream("/Users/hatarinshou/IdeaProjects/demo-projects/jar-version-statistics/jar-version-statistics/src/main/resources/template.xlsx");
        XSSFWorkbook workbook=new XSSFWorkbook(fileInputStream);
        final XSSFSheet sheet1 = workbook.getSheet("Sheet1");
        final XSSFRow row = sheet1.getRow(0);
        final XSSFCell cell = row.getCell(0);
        final String stringCellValue = cell.getStringCellValue();
        System.out.println(stringCellValue);
    }

    @Test
    public void test7() throws Exception{
        FileInputStream fileInputStream = new FileInputStream("/Users/hatarinshou/IdeaProjects/demo-projects/jar-version-statistics/jar-version-statistics/src/main/resources/template.xlsx");
        XSSFWorkbook workbook=new XSSFWorkbook(fileInputStream);
        XSSFSheet sheet = workbook.getSheet("Sheet1");
//        sheet.getRow(2).getCell(1).setCellValue("人民");

        sheet.createRow(2).createCell(0).setCellValue("国务院");
        workbook.write(new FileOutputStream("/Users/hatarinshou/IdeaProjects/demo-projects/jar-version-statistics/jar-version-statistics/src/main/resources/template.xlsx"));
        System.out.println("success");
    }

    @Test
    public void test8(){
        String s="[INFO] Finished at: 2020-07-31T09:18:13+08:00";
        String s2="[INFO] |  |  |  +- org.springframework:spring-aop:jar:4.3.6.RELEASE:compile";
        boolean validMavenDependencyStr = StringUtil.isValidMavenDependencyStr(s2);
        System.out.println(validMavenDependencyStr);
    }

}
